<?php
require_once 'common/config.php';
require_once 'common/functions.php';

// 检查登录状态
check_login();

$db = db_connect();

// 获取预约ID
$booking_id = isset($_GET['id']) ? intval($_GET['id']) : 0;

// 获取预约详情
$sql = "SELECT b.*, c.name as course_name, u.name as user_name, u.phone as user_phone, 
        u.email as user_email, u.gender as user_gender, 
        co.name as coach_name, c.description as course_description, c.price as course_price
        FROM bookings b 
        LEFT JOIN courses c ON b.course_id = c.id 
        LEFT JOIN users u ON b.user_id = u.id 
        LEFT JOIN coaches co ON c.coach_id = co.id 
        WHERE b.id = :booking_id";
$stmt = $db->prepare($sql);
$stmt->bindValue(':booking_id', $booking_id);
$stmt->execute();
$booking = $stmt->fetch(PDO::FETCH_ASSOC);

// 如果没有找到预约记录，重定向到预约列表
if (!$booking) {
    header('Location: course_bookings.php');
    exit;
}
?>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>预约详情 - <?php echo SITE_NAME; ?></title>
    <link rel="stylesheet" href="assets/css/style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <style>
        .top-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }
        .top-header h2 {
            margin: 0;
            font-size: 24px;
            color: #333;
        }
        .details-card {
            background: #f9f9f9;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
            margin-bottom: 20px;
        }
        .details-card h3 {
            margin-bottom: 15px;
            font-size: 20px;
            color: #333;
        }
        .details-card p {
            margin: 10px 0;
            font-size: 16px;
            color: #555;
        }
        .badge {
            padding: 5px 10px;
            border-radius: 4px;
            font-size: 12px;
            font-weight: 500;
        }
        .badge-success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        .badge-danger {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        .actions {
            margin-top: 20px;
        }
        .btn {
            padding: 10px 15px;
            border-radius: 4px;
            text-decoration: none;
            color: #fff;
            background: #3498db;
            transition: background 0.3s;
        }
        .btn:hover {
            background: #2980b9;
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <?php include 'includes/sidebar.php'; ?>
        
        <div class="main-content">
            <header class="top-header">
                <div class="header-left">
                    <h2>预约详情</h2>
                </div>
            </header>

            <div class="content">
                <div class="details-card">
                    <h3>用户信息</h3>
                    <p><strong>用户姓名:</strong> <?php echo htmlspecialchars($booking['user_name']); ?></p>
                    <p><strong>用户手机号:</strong> <?php echo htmlspecialchars($booking['user_phone']); ?></p>
                    <p><strong>用户邮箱:</strong> <?php echo htmlspecialchars($booking['user_email']); ?></p>
                    <p><strong>用户性别:</strong> <?php echo htmlspecialchars($booking['user_gender']); ?></p>
                </div>

                <div class="details-card">
                    <h3>课程信息</h3>
                    <p><strong>课程名称:</strong> <?php echo htmlspecialchars($booking['course_name']); ?></p>
                    <p><strong>教练:</strong> <?php echo htmlspecialchars($booking['coach_name']); ?></p>
                    <p><strong>课程描述:</strong> <?php echo htmlspecialchars($booking['course_description']); ?></p>
                    <p><strong>课程价格:</strong> ¥<?php echo number_format($booking['course_price'], 2); ?></p>
                    <p><strong>预约时间:</strong> <?php echo date('Y-m-d H:i', strtotime($booking['created_at'])); ?></p>
                    <p><strong>状态:</strong> 
                        <span class="badge <?php echo $booking['status'] ? 'badge-success' : 'badge-danger'; ?>">
                            <?php echo $booking['status'] ? '已确认' : '未确认'; ?>
                        </span>
                    </p>
                </div>

                <div class="actions">
                    <a href="course_bookings.php" class="btn btn-secondary">
                        <i class="fas fa-arrow-left"></i> 返回预约列表
                    </a>
                </div>
            </div>
        </div>
    </div>
</body>
</html> 